using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using MacomberMap.Common.Components;

namespace MacomberMap.Common.Events
{
    /// <summary>
    /// This class holds information on invalid GUIDs
    /// </summary>
    public class MM_Event_InvalidGUID: MM_Event
    {
        #region Variable declarations
        /// <summary>The string of the bad GUID</summary>
        public String BadGUID;

        /// <summary>The ID that was created for the bad GUID</summary>
        public MM_rdfID BadID;

        /// <summary>The exception that occurred when parsing</summary>
        public Exception Error;
        #endregion

        #region Initialization
        /// <summary>
        /// Initialize a new invalid GUID placeholder
        /// </summary>
        /// <param name="BadGUID">The bad GUID</param>
        /// <param name="BadID">The ID associated with the bad GUID</param>
        /// <param name="Error">The exception that occurred during parsing</param>        
        public MM_Event_InvalidGUID(String BadGUID, MM_rdfID BadID, Exception Error)
        {
            this.BadGUID = BadGUID;
            this.BadID = BadID;
            this.Error = Error;
        }
        #endregion

        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="OutMenu"></param>
        public override void AddMenuItems(ContextMenuStrip OutMenu)
        {
            //throw new Exception("The method or operation is not implemented.");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ListViewItem BuildListViewItem()
        {
            ListViewItem NewItem = new ListViewItem(BadGUID);                
            NewItem.SubItems.Add(this.EventState.ToString());
            NewItem.SubItems.Add(TimeText);
            NewItem.ImageIndex = EventType.Index;
            return NewItem;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lvItem"></param>
        public override void UpdateListViewItem(ListViewItem lvItem)
        {
            lvItem.SubItems[0].Text = BadGUID;
            lvItem.SubItems[1].Text = EventState.ToString();
            lvItem.SubItems[2].Text = TimeText;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="OutParent"></param>
        public override void DisplayDetails(Control OutParent)
        {
            TreeView tvOut = new TreeView();
            tvOut.Dock = DockStyle.Fill;
            this.AddNodeItem("Bad GUID", BadGUID, tvOut.Nodes);            
            this.AddNodeItem("Exception", Error, tvOut.Nodes);
            tvOut.Nodes[0].EnsureVisible();
            OutParent.Controls.Add(tvOut);
        }

        /// <summary>
        /// Compare the bad GUIDs
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override int CompareTo(object obj)
        {
            return BadGUID.CompareTo((obj as MM_Event_InvalidGUID).BadGUID);
        }
        
    }
}
